﻿using System;
using System.Linq;

namespace LaoLuo
{
    /// <summary>
    /// 12生肖
    /// </summary>
    public enum ChineseZodiac
    {
        /// <summary>
        /// 鼠
        /// </summary>
        鼠 = 1,

        /// <summary>
        /// 牛
        /// </summary>
        牛 = 2,

        /// <summary>
        /// 虎
        /// </summary>
        虎 = 3,

        /// <summary>
        /// 兔
        /// </summary>
        兔 = 4,

        /// <summary>
        /// 龙
        /// </summary>
        龙 = 5,

        /// <summary>
        /// 蛇
        /// </summary>
        蛇 = 6,

        /// <summary>
        /// 马
        /// </summary>
        马 = 7,

        /// <summary>
        /// 羊
        /// </summary>
        羊 = 8,

        /// <summary>
        /// 猴
        /// </summary>
        猴 = 9,

        /// <summary>
        /// 鸡
        /// </summary>
        鸡 = 10,

        /// <summary>
        /// 狗
        /// </summary>
        狗 = 11,

        /// <summary>
        /// 猪
        /// </summary>
        猪 = 12
    }

    /// <summary>
    /// 提供12生肖相关的扩展方法
    /// </summary>
    public static class ChineseZodiacExtensions
    {
        /// <summary>
        /// 获取数字对应的生肖
        /// </summary>
        /// <param name="value">要获取对应生肖的数字</param>
        /// <returns>数字对应的生肖奥</returns>
        public static ChineseZodiac ToChineseZodiac(this int value)
        {
            return TypeConverter.ToType<ChineseZodiac>(value);
        }

        /// <summary>
        /// 获取字符串对应的生肖
        /// </summary>
        /// <param name="value">要获取对应生肖的字符串</param>
        /// <returns>字符串对应的生肖奥</returns>
        public static ChineseZodiac ToChineseZodiac(this string value)
        {
            return TypeConverter.ToType<ChineseZodiac>(value);
        }

        /// <summary>
        /// 获取时间对应的生肖
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static ChineseZodiac GetChineseZodiac(this DateTime value)
        {
            return EnumHelper.GetAllEnumValues<ChineseZodiac>().ToArray()[Math.Abs(value.Year - 1900) % 12];
        }

        /// <summary>
        /// 获取年份对应的生肖
        /// </summary>
        /// <param name="year"></param>
        /// <returns></returns>
        public static ChineseZodiac GetChineseZodiac(this int year)
        {
            return EnumHelper.GetAllEnumValues<ChineseZodiac>().ToArray()[Math.Abs(year - 1900) % 12];
        }
    }
}
